package toDo.app.controllers;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.Button;
import android.widget.TextView;

public class TextMatcher implements TextWatcher{
	TextView matchOne;
	TextView matchTwo;
	TextView status;
	Button result;
	String isMatch;
	String noMatch;
	
	public TextMatcher(TextView matchOne, TextView matchTwo){
		this.matchOne = matchOne;
		this.matchTwo = matchTwo;
	}
	
	public TextMatcher setString(String isMatch, String noMatch){
		this.isMatch = isMatch;
		this.noMatch = noMatch;
		return this;
	}
	
	public TextMatcher setStatusLabel(TextView status){
		this.status = status;
		return this;
	}
	
	public TextMatcher setResultEnable(Button result){
		this.result = result;
		return this;
	}
	
	@Override
	public void afterTextChanged(Editable s) {
		boolean match = matchOne.getText().toString().equals(matchTwo.getText().toString()); 
			if(status != null)	{
				if(match){
					status.setText(isMatch);
				} else {
					status.setText(noMatch);
				}
			}
			if(result != null){
				if(match){
					result.setEnabled(true);
				} else {
					result.setEnabled(false);
				}
				
			} 
	}

	@Override
	public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

	@Override
	public void onTextChanged(CharSequence s, int start, int before, int count) {}

}
